home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Template.c
-
- Copyright: © 1997-1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- //
- // You may incorporate this sample code into your applications
- // without restriction. This sample code has been provided "AS
- // IS" and the responsibility for its operation is 100% yours.
- // You are not permitted to redistribute the source as "Apple
- // sample code" after having made changes. If you're going to
- // re-distribute the source, we require that you make it clear
- // in the source that the code was descended from Apple sample
- // code, but that you've made changes.
- //
-
- #pragma segment AppSeg
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif
-
- #ifndef Common_Defs
- #include "Common.h"
- #endif
-
- short gQuit, gQuitting;
- short gDocumentCount;
- Document* gDocumentList[kMaxDocumentCount];
- short gFontItem, gSizeItem;
- short gInBackground;
- Document* gFrontDocument;
- short gCanUndoDrag;
- WindowPtr gUndoFrontmost, gLastFrontmost;
- Boolean gCanDrag;
- Boolean gCanPrint;
- THPrint gPrintRecord;
- Boolean gNavServicesExists;
-
- // AppleEvent handlers:
- AEEventHandlerUPP myODOCEventHandler;
- AEEventHandlerUPP myQAPPEventHandler;
- AEEventHandlerUPP myOAPPEventHandler;
- ControlActionUPP myActionProcUPP;
-
- // for MixedMode:
- #ifndef NewEventHandlerProc
- #define NewEventHandlerProc(x) (EventHandlerProcPtr)x
- #endif
-
- // prototypes:
- void InitializeToolbox(void);
- void InitializeGlobals(void);
- void SetupMenus(void);
- void InstallEventHandlers(void);
-
-
- // *****************************************************************************
- // *
- // * InitializeToolbox()
- // *
- // *****************************************************************************
- void InitializeToolbox()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- MoreMasters();
- MoreMasters();
- MaxApplZone();
-
- FlushEvents(everyEvent,0);
- }
-
-
- // *****************************************************************************
- // *
- // * InitializeGlobals()
- // *
- // *****************************************************************************
- void InitializeGlobals()
- {
- long result = 0;
-
- gQuit = gQuitting = false;
- gDocumentCount = 0;
- gFontItem = gSizeItem = 0;
- gInBackground = false;
- gCanUndoDrag = slCantUndo;
- gPrintRecord = nil;
-
- if ((Gestalt(gestaltDragMgrAttr,&result) != noErr) || (!(result & (1 << gestaltDragMgrPresent))))
- gCanDrag = false;
- else
- gCanDrag = true;
-
- gCanPrint = false;
-
- // Check for Navigation Services
- gNavServicesExists = NavServicesAvailable();
- }
-
-
- // *****************************************************************************
- // *
- // * SetupMenus()
- // *
- // *****************************************************************************
- void SetupMenus()
- {
- Handle theMenuBar;
- Str255 theStr;
-
- theMenuBar = GetNewMBar(MenuBarID);
-
- SetMenuBar(theMenuBar);
- DisposeHandle(theMenuBar);
-
- AppendResMenu(GetMenuHandle(idAppleMenu),'DRVR');
-
- GetIndString(theStr,MenuStringsID,slCantUndo);
- SetMenuItemText(GetMenuHandle(idEditMenu),iUndo,theStr);
-
- DrawMenuBar();
- }
-
-
- // *****************************************************************************
- // *
- // * InstallEventHandlers()
- // *
- // *****************************************************************************
- void InstallEventHandlers()
- {
- long result = 0;
- OSErr theErr = noErr;
-
- theErr = Gestalt(gestaltAppleEventsAttr,&result);
- if (theErr == noErr)
- {
- myODOCEventHandler = NewAEEventHandlerProc(MyHandleODOC);
- myQAPPEventHandler = NewAEEventHandlerProc(MyHandleQUIT);
- myOAPPEventHandler = NewAEEventHandlerProc(MyHandleOAPP);
-
- (void)AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,myOAPPEventHandler,0,false);
- (void)AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,myQAPPEventHandler,0,false);
- (void)AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,myODOCEventHandler,0,false);
- }
- }
-
-
- // *****************************************************************************
- main()
- {
- long result = 0;
- OSErr theErr = noErr;
-
- InitializeToolbox();
- InitializeGlobals();
- InstallEventHandlers();
- SetupMenus();
-
- myActionProcUPP = NewControlActionProc(ScrollProc);
-
- AdjustMenus();
-
- EventLoop();
-
- theErr = Gestalt(gestaltAppleEventsAttr,&result);
- if (theErr != noErr)
- {
- DisposeRoutineDescriptor(myODOCEventHandler);
- DisposeRoutineDescriptor(myQAPPEventHandler);
- DisposeRoutineDescriptor(myOAPPEventHandler);
- }
-
- DisposeRoutineDescriptor(myActionProcUPP);
-
- return 0;
- }
-